import { Body, Controller, Get, Ip, Post } from '@nestjs/common'
import { IUser } from 'src/config/constants/IUser'
import { ResultData } from 'src/config/constants/ResultData'
import { User } from 'src/config/decorator/admin-user.decorator'
import { Authorize } from 'src/config/decorator/authorize.decorator'
import { createImageCodeDto, userLoginDto, userRegisterDto } from './user.dto'
import { UserService } from './user.service'

@Controller('user')
export class UserController {
  constructor(private readonly userService: UserService) { }

  @Authorize()
  @Post('/createImageCode')
  async createImageCode(@Body() data: createImageCodeDto) {
    const resultData = { image: await this.userService.generateCode(data.murmur) }

    return ResultData.ok({ data: resultData })
  }

  @Authorize()
  @Post('/userRegister')
  async userRegister(@Body() data: userRegisterDto) {
    return await this.userService.userRegister(data)
  }


  @Authorize()
  @Post('/userLogin')
  async userLogin(@Body() data: userLoginDto, @Ip() ip: string) {
    return await this.userService.userLogin(data, ip)
  }

  @Get('/getUserData')
  async getUserData(@User() data: IUser, @Ip() ip: string) {
    return await this.userService.getUserData(data, ip)
  }
}

